package o;

import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean.e;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

class cvz {
    private boolean ˊ = true;
    private cwb ˋ;

    public cvz(cwb o_cwb) {
        this.ˋ = o_cwb;
    }

    boolean ॱ() {
        return this.ˊ;
    }

    void ˏ(boolean z) {
        this.ˊ = z;
    }

    ResponseBean ˎ(ResponseBean responseBean) {
        if (responseBean != null) {
            return responseBean;
        }
        responseBean = new ResponseBean();
        ResponseBean.setResponseCode(responseBean, 5);
        ResponseBean.setErrCause(responseBean, e.PARAM_ERROR);
        responseBean.setDnsReachable(ॱ());
        return responseBean;
    }

    void ˎ(ResponseBean responseBean, Exception exception) {
        if (responseBean == null || (exception instanceof IllegalAccessException)) {
            ˋ(responseBean, 1, e.UNKNOWN_EXCEPTION, exception);
            cvp.ˎ.ˊ("ResponseHandler", "filterResponseException, response = " + responseBean);
        } else if ((exception instanceof IllegalArgumentException) || (exception instanceof MalformedURLException)) {
            ˋ(responseBean, 5, e.PARAM_ERROR, exception);
        } else {
            if (ॱ()) {
                int ˏ = dmv.ˏ(responseBean.getResponseCode(), exception);
                if (ˏ > 0) {
                    ˋ(responseBean, 1, e.CONNECT_EXCEPTION, exception);
                    ॱ(exception, ˏ);
                }
            } else {
                ˋ(responseBean, 3, e.NO_NETWORK, exception);
            }
            this.ˋ.ˋ(BaseRequest.getReqUrl(this.ˋ.ˎ()), exception);
        }
    }

    void ˋ(ResponseBean responseBean, int i, e eVar, Exception exception) {
        if (responseBean != null) {
            responseBean.setDnsFailType(dmv.ˏ(0, exception));
            ResponseBean.setResponseCode(responseBean, i);
            ResponseBean.setErrCause(responseBean, eVar);
        }
    }

    private void ॱ(Exception exception, int i) {
        try {
            String host = new URL(this.ˋ.ˎ().getUrl()).getHost();
            if (doo.ॱ(host)) {
                cvp.ˎ.ˊ("ResponseHandler", "updateRequestByDNSBackupIfNeeded error");
                return;
            }
            List ˎ = dmv.ˎ(host, exception, i);
            if (ˎ.size() > 0) {
                this.ˋ.ˏ(ˎ);
                cvp.ˎ.ˋ("DNKEEPER", "url updated by dnsBacup");
            }
        } catch (Throwable e) {
            cvp.ˎ.ˊ("ResponseHandler", "updateRequestByDNSBackupIfNeeded exception", e);
        }
    }
}
